// pages/canteen/login/login.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  onClickLeft() {
    wx.navigateBack()
  },

  onChange(event) {
    // console.log(event)
    var that = this;
    if(event.currentTarget.id=="password") {
      if(event.detail.length < 5) {
        that.setData({
          pwdMsg: "密码长度小于五位"
        })
      }else {
        that.setData({
          pwdMsg: ""
        })
      }
    }else{
      if(event.detail.length == 0) {
        that.setData({
          accMsg: "账号不能为空"
        })
      }else {
        that.setData({
          accMsg: ""
        })
      }
    }
  },

  formSubmit (e) {
    var that = this;
    // console.log('表单提交数据', e.detail.value)
    var userAccount = e.detail.value.userAccount;
    var password = e.detail.value.password;
    if(userAccount.length == 0) {
      that.setData({
        accMsg: "账号不能为空"
      })
    }
    if(password.length < 5) {
      that.setData({
        pwdMsg: "密码长度小于五位"
      })
    }

    // console.log('进行用户登录的判断')
    // if(userAccount.length != 0 && password.length >= 5) {
    //   if(userAccount=="zs" && password=="123456") {
    //     wx.navigateTo({
    //       url: '../index/index?name=张三',
    //     })
    //   }else {
    //     that.setData({
    //       pwdMsg: "密码错误"
    //     })
    //   }
    // }
    console.log(userAccount);
    console.log(password);
    const db = wx.cloud.database()
    db.collection('root').where({
      account: userAccount,
      password: password
    })
    .get({
      success: function(res) {
        wx.navigateTo({
          url: '/pages/root/auditing/auditing',
        })

      }
    })
  },
})